package com.cloudeye.business_study;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * Created by lafangyuan on 2021/6/18.
 */
public class Java8 {

    public static void main(String[] args) {
        testHappy();
    }
    private static void testHappy(){
        happy(2,(m)-> System.out.println("花衣服买了"+m+"元"));
    }

    /**
     * Consumer<T> void accept(T t),接受一个输入参数并且无返回的操作
     * @param money
     * @param consumer
     */
    private static void happy(double money, Consumer<Double> consumer){
        consumer.accept(money);
    }

    /**
     * Supplier<T>  供给型接口，T get()； 返回一个接口
     * @param num
     * @param supplier
     * @return
     */
    private static List<Integer> getNumList(int num, Supplier<Integer> supplier){
        List<Integer> list = new ArrayList<>();
        for(int i=0;i<num;i++){
            list.add(supplier.get());
        }
        return list;
    }

    /**
     * 函数型接口
     * Function<T,R>: T:入参类型，R：返回参数类型； R apply(t)
     * @param s
     * @param function
     * @return
     */
    private static Integer toUpper(String s, Function<String,Integer> function){
        return function.apply(s);
    }

    /**
     * 断言型接口：Predicate<T>  boolean test(t)
     * @param list
     * @param predicate
     * @return
     */
    private static List<Integer> add(List<Integer> list, Predicate<Integer> predicate){
        List<Integer> data = new ArrayList<>();
        for(Integer a:list){
            if(predicate.test(a)){
                data.add(a);
            }
        }
        return data;
    }
}
